package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import factory.DAOFactory;

/**
 * Servlet implementation class OrderAccepedServlet
 */
@WebServlet("/OrderAcceptedServlet")
public class OrderAcceptedServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public OrderAcceptedServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String id = request.getParameter("id");
		int order_id = Integer.valueOf(id);
		if(DAOFactory.getOrdersDAOInstance().orderAccepted(order_id)) {
			response.getWriter().println("<script LANGUAGE='javascript'> alert('接单成功！');history.go(-1);</script>");
			response.sendRedirect("store_order.jsp");
		}else {
			response.getWriter().println("<script LANGUAGE='javascript'> alert('接单失败！');history.go(-1);</script>");
			response.sendRedirect("store_order.jsp");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
